// ==================================================================================
// Shared Genomics Project MPI Codebase
// Version 1.0 30/04/2010
//
// (c) 2010 University of Manchester all rights reserved
//
// This file is distributed under the GNU General Public License, Version 2.  
// Please see the file COPYING.txt for more details
// ==================================================================================

#ifndef _IPEDFILE_H_
#define _IPEDFILE_H_

#include "pedfile.h"
#include "options.h"

#ifdef __cplusplus
extern "C" {
#endif

/*!
\file
\ingroup	gio
\brief		Individual-Major Allelic Bitstring array 
\details
	A file containing an Individual-Major Allelic Bitstring array is referred as an IPED file
	in this documentation.<br>
	To create an IPED file, a genomic data-set (\ref mapfile) must be converted 
	from SNP-major to Individual-Major format (\ref pedfile) by a call to \ref snp_to_ind().<br>
	A IPED file has typically the suffix \ref SUFFIX_IPED_FILE.
\see snp_to_ind()
*/

/*!
\brief Create an IPED file.
\details The path to the output file is bound to the variable \ref selected_options::szIpedFileName.
\param [in] ops Location of the output file
\param [in] p Source genomic data-set
\returns 1 on success, 0 on failure
*/
int ipedfile_create(struct selected_options *ops, struct pedfile *p);

/*!
\brief Load an IPED file.
\details The path to the input file is bound to the variable \ref selected_options::szIpedFileName.
\param [in] ops Location of the input file
\param [in,out] nSamples Pointer to store No. Samples/People in a data-set.
\param [in,out] nSNPs Pointer to store No. SNPs in a data-set.
\param [in,out] nRecordBytes Bitstring size in bytes allocated to each person in a data-set.
\returns char/byte array or NULL on failure
*/
char* ipedfile_load(struct selected_options *ops, int *nSamples, int *nSNPs, int *nRecordBytes);

/*! 
\brief Create an IPED file and copy to remote directory
\details
	The output filename is a concatonation of \ref selected_options::rdir, \ref selected_options::szRunId
	and \ref SUFFIX_IPED_FILE .<br>
\param [in] ops Output file location
\param [in] p Genomic data-set to write to file
\param [in] rank Local processor rank
\returns 1 on success, 0 on failure
*/
int ipedfile_create_and_copy(struct selected_options *ops, struct pedfile *p, int rank);

#ifdef __cplusplus
}
#endif

#endif // _IPEDFILE_H_
